using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using OVS.BusinessObjects;

namespace OVS.DAL
{
	public partial class ConfigDAO
	{
		public ConfigDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<Config> GetConfigs()
		{
			try
			{
				List<Config> lstConfigs = new List<Config>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [conf_id],[conf_fn_video],[conf_fn_images],[conf_fn_haar],[conf_fn_images_traj],[conf_fn_mail],[conf_fn_serv],[conf_fn_log],[conf_fn_pwd] FROM [Config]",CommandType.Text);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					Config oConfig = new Config();
					oConfig.conf_id = Convert.ToInt32(oDbDataReader["conf_id"]);

					if(oDbDataReader["conf_fn_video"] != DBNull.Value)
						oConfig.conf_fn_video = Convert.ToString(oDbDataReader["conf_fn_video"]);

					if(oDbDataReader["conf_fn_images"] != DBNull.Value)
						oConfig.conf_fn_images = Convert.ToString(oDbDataReader["conf_fn_images"]);

					if(oDbDataReader["conf_fn_haar"] != DBNull.Value)
						oConfig.conf_fn_haar = Convert.ToString(oDbDataReader["conf_fn_haar"]);

					if(oDbDataReader["conf_fn_images_traj"] != DBNull.Value)
						oConfig.conf_fn_images_traj = Convert.ToString(oDbDataReader["conf_fn_images_traj"]);

					if(oDbDataReader["conf_fn_mail"] != DBNull.Value)
						oConfig.conf_fn_mail = Convert.ToString(oDbDataReader["conf_fn_mail"]);

					if(oDbDataReader["conf_fn_serv"] != DBNull.Value)
						oConfig.conf_fn_serv = Convert.ToString(oDbDataReader["conf_fn_serv"]);

					if(oDbDataReader["conf_fn_log"] != DBNull.Value)
						oConfig.conf_fn_log = Convert.ToString(oDbDataReader["conf_fn_log"]);

					if(oDbDataReader["conf_fn_pwd"] != DBNull.Value)
						oConfig.conf_fn_pwd = Convert.ToString(oDbDataReader["conf_fn_pwd"]);
					lstConfigs.Add(oConfig);
				}
				oDbDataReader.Close();
				return lstConfigs;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public Config GetConfig(int conf_id)
		{
			try
			{
				Config oConfig = new Config();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [conf_id],[conf_fn_video],[conf_fn_images],[conf_fn_haar],[conf_fn_images_traj],[conf_fn_mail],[conf_fn_serv],[conf_fn_log],[conf_fn_pwd] FROM [Config] WHERE [conf_id]=@conf_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_id",DbType.Int32,conf_id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oConfig.conf_id = Convert.ToInt32(oDbDataReader["conf_id"]);

					if(oDbDataReader["conf_fn_video"] != DBNull.Value)
						oConfig.conf_fn_video = Convert.ToString(oDbDataReader["conf_fn_video"]);

					if(oDbDataReader["conf_fn_images"] != DBNull.Value)
						oConfig.conf_fn_images = Convert.ToString(oDbDataReader["conf_fn_images"]);

					if(oDbDataReader["conf_fn_haar"] != DBNull.Value)
						oConfig.conf_fn_haar = Convert.ToString(oDbDataReader["conf_fn_haar"]);

					if(oDbDataReader["conf_fn_images_traj"] != DBNull.Value)
						oConfig.conf_fn_images_traj = Convert.ToString(oDbDataReader["conf_fn_images_traj"]);

					if(oDbDataReader["conf_fn_mail"] != DBNull.Value)
						oConfig.conf_fn_mail = Convert.ToString(oDbDataReader["conf_fn_mail"]);

					if(oDbDataReader["conf_fn_serv"] != DBNull.Value)
						oConfig.conf_fn_serv = Convert.ToString(oDbDataReader["conf_fn_serv"]);

					if(oDbDataReader["conf_fn_log"] != DBNull.Value)
						oConfig.conf_fn_log = Convert.ToString(oDbDataReader["conf_fn_log"]);

					if(oDbDataReader["conf_fn_pwd"] != DBNull.Value)
						oConfig.conf_fn_pwd = Convert.ToString(oDbDataReader["conf_fn_pwd"]);
				}
				oDbDataReader.Close();
				return oConfig;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddConfig(Config oConfig)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Config]([conf_fn_video],[conf_fn_images],[conf_fn_haar],[conf_fn_images_traj],[conf_fn_mail],[conf_fn_serv],[conf_fn_log],[conf_fn_pwd])VALUES(@conf_fn_video,@conf_fn_images,@conf_fn_haar,@conf_fn_images_traj,@conf_fn_mail,@conf_fn_serv,@conf_fn_log,@conf_fn_pwd);SELECT SCOPE_IDENTITY();",CommandType.Text);
				if (oConfig.conf_fn_video!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_video",DbType.String,oConfig.conf_fn_video));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_video",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_images!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_images",DbType.String,oConfig.conf_fn_images));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_images",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_haar!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_haar",DbType.String,oConfig.conf_fn_haar));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_haar",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_images_traj!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_images_traj",DbType.String,oConfig.conf_fn_images_traj));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_images_traj",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_mail!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_mail",DbType.String,oConfig.conf_fn_mail));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_mail",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_serv!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_serv",DbType.String,oConfig.conf_fn_serv));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_serv",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_log!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_log",DbType.String,oConfig.conf_fn_log));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_log",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_pwd!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_pwd",DbType.String,oConfig.conf_fn_pwd));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_pwd",DbType.String,DBNull.Value));

				return Convert.ToInt32(DbProviderHelper.ExecuteScalar(oDbCommand));
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateConfig(Config oConfig)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Config] SET [conf_fn_video]=@conf_fn_video,[conf_fn_images]=@conf_fn_images,[conf_fn_haar]=@conf_fn_haar,[conf_fn_images_traj]=@conf_fn_images_traj,[conf_fn_mail]=@conf_fn_mail,[conf_fn_serv]=@conf_fn_serv,[conf_fn_log]=@conf_fn_log,[conf_fn_pwd]=@conf_fn_pwd WHERE [conf_id]=@conf_id",CommandType.Text);
				if (oConfig.conf_fn_video!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_video",DbType.String,oConfig.conf_fn_video));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_video",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_images!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_images",DbType.String,oConfig.conf_fn_images));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_images",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_haar!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_haar",DbType.String,oConfig.conf_fn_haar));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_haar",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_images_traj!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_images_traj",DbType.String,oConfig.conf_fn_images_traj));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_images_traj",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_mail!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_mail",DbType.String,oConfig.conf_fn_mail));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_mail",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_serv!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_serv",DbType.String,oConfig.conf_fn_serv));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_serv",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_log!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_log",DbType.String,oConfig.conf_fn_log));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_log",DbType.String,DBNull.Value));
				if (oConfig.conf_fn_pwd!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_pwd",DbType.String,oConfig.conf_fn_pwd));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_fn_pwd",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_id",DbType.Int32,oConfig.conf_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveConfig(Config oConfig)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Config] WHERE [conf_id]=@conf_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_id",DbType.Int32,oConfig.conf_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveConfig(int conf_id)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Config] WHERE [conf_id]=@conf_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@conf_id",DbType.Int32,conf_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
